<%@page import="com.webdemo3.bean.UsersBean" %>
<%@page import="com.webdemo3.dao.UsersDao" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String username, password, flag;
	username = request.getParameter("username");
	password = request.getParameter("password");
	flag = request.getParameter("flag");
	String errorCode = new String("0");
	UsersBean ub = UsersDao.usersLogin(username);
	if(ub != null) {
		if(username.equals(ub.getUsername()) && password.equals(ub.getPwd())) {
			if(flag != null) {
				Cookie cookie = new Cookie("username", username);
				cookie.setMaxAge(3600*24*30);
				response.addCookie(cookie);
			}
			session.setAttribute("username", username);
			response.sendRedirect("list.jsp?username=" + username);
		} else {
			errorCode = "2";
			response.sendRedirect("index.jsp?errorCode=" + errorCode);
		}
	} else {
		errorCode = "1";
		response.sendRedirect("index.jsp?errorCode=" + errorCode);
	}
%>
